package com.lan.mock13.shengsai.tD;

import java.util.*;

class Node {
	public int num;
	public int score;
	
	public Node(int num, int score) {
		this.num = num;
		this.score = score;
	}

	@Override
	public String toString() {
		return "Node [num=" + num + ", score=" + score + "]";
	}
	
}

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		Node[] p = new Node[n];
		
		for (int i = 0; i < n; i ++) {
			int score = 0;
			int t = i + 1;
			while(t > 0) {
				score += t % 10;
				t /= 10;
			}
			p[i] = new Node(i + 1, score);
		}
		
		Arrays.sort(p, (a, b) -> {
				if (a.score != b.score) {
					return a.score - b.score;
				}
				return a.num - b.num;
			}
		);		
		System.out.println(p[m - 1].num);
	}
}
